home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11124 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: newshost.cyberramp.net!news
  2. From: sinan@cyberramp.net (John Noland)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: HELP!! with file read/write
  5. Date: 22 Mar 1996 01:53:59 GMT
  6. Organization: Prose Software
  7. Message-ID: <4it17n$jkf@newshost.cyberramp.net>
  8. References: <4iijmh$brs@cloner2.ix.netcom.com>
  9. NNTP-Posting-Host: ramp1-6.cyberramp.net
  10. X-Newsreader: WinVN 0.99.5
  11.  
  12. In article <4iijmh$brs@cloner2.ix.netcom.com>, scoshe@ix.netcom.co says...
  13.  
  14. I'll forgive you the C++ style comments, I'm certain you'll hear about them.
  15.  
  16. There are several problems: I assume you left out your header files from
  17. this example for brevity? The declaration of struct _items? The declaration
  18. and/or definition of itemsize? 
  19. These problems aside,
  20. If you open a file for update(read/write), when you switch between reading and
  21. writing, there must be an intervening fflush, fsetpos, fseek or rewind 
  22. operation. You lack this after your write.
  23.  
  24.  
  25. >void daily_maintainence()
  26. >{
  27. >  FILE *itemfile;
  28. >  long  filepos;
  29. >  struct _items item;
  30. >  itemfile=fopen("items.dat","r+b");          //open for read and write
  31. >  while (fread(&item,itemsize,1,itemfile)==1)
  32. >  {
  33. >    filepos=ftell(itemfile);                  //for debug
  34. >    item.today=0;                             //set to zero
  35. >    item.daysleft--;                          //decrement
  36. >    fseek(itemfile,-itemsize,SEEK_CUR);       //seek to where this rec
  37. >starts
  38. >    filepos=ftell(itemfile);                  //for debug
  39. >    fwrite(&item,itemsize,1,itemfile);        //write it out
  40. >    filepos=ftell(itemfile);                  //for debug
  41. >  }
  42. >}
  43.  
  44.